package com.linkin.homepage.app;

import android.content.Context;

import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.linkin.homepage.base.util.Predictor;
import com.linkin.homepage.bean.ExamDataBean;
import com.linkin.homepage.bean.HomeDataResponse;
import com.linkin.homepage.util.AssetUtil;

import java.util.List;

public class PreloadApi {

    private static final String MAIN_TABS = "MAIN_TABS";
    private static final String MAIN_TABS_VERSION = "MAIN_TABS_VERSION";

    private static final String NEWS_CHANNELS = "NEWS_CHANNELS";
    private static final String NEWS_CHANNELS_VERSION = "NEWS_CHANNELS_VERSION";


    private static HomeDataResponse mHomeDataResponse = null;
    private static HomeDataResponse.HomeDataInfo mHomeData;

    public static void initData(Context context) {
        String jsonData = AssetUtil.Companion.getAssetJsonFile(context);
        mHomeDataResponse = new Gson().fromJson(jsonData, HomeDataResponse.class);
    }

    @Nullable
    public static HomeDataResponse.HomeDataInfo getHomeData() {
        if (mHomeDataResponse != null && mHomeDataResponse.check()) {
            mHomeData = mHomeDataResponse.data;
            return mHomeData;
        }
        return null;
    }

    public static List<ExamDataBean> getExamData() {
        if (mHomeData != null && Predictor.isNotEmpty(mHomeData.exam_data)) {
            return mHomeData.exam_data;
        }

        return null;
    }


}
